import datetime
import os.path
import time

import cv2
from robomaster import robot
from identify2 import *


def log(*text):
    text = str(datetime.datetime.now())[:19] + '--' + ', '.join([str(i) for i in text])
    print(text)
    return text + '\n\n'


robot.config.LOCAL_IP_STR = "192.168.10.2"

tl_drone = robot.Drone()
tl_drone.initialize()

tl_camera = tl_drone.camera

# tl_camera.start_video_stream(display=True)
# time.sleep(10)
# tl_camera.stop_video_stream()

tl_camera.start_video_stream(display=False)
tl_camera.set_fps("high")
tl_camera.set_resolution("high")
tl_camera.set_bitrate(6)
if not os.path.exists('imgs'):
    os.mkdir('imgs')
# for i in range(0, 150):
i = 0
while True:
    img = tl_camera.read_cv2_image()
    cv2.waitKey(1)
    # img = object_detection_api(img)
    gaussian_img = gaussian_blur(img)
    gray_img = gray_procession(gaussian_img)
    threshold_img = threshold_procession(gray_img, 110)
    # draw_shape(threshold_img, img)
    # cv2.imshow("Drone", img)
    cv2.imwrite('imgs/{}.jpg'.format(i), img)
    i += 1

tl_camera.stop_video_stream()

tl_drone.close()
